﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KeywordAuction.Utility
{
    public static class AdspotFactory
    {
        public static Adspot Create(AuctionHost host, int? traffic = null,int locationCount = 2, List<double> ctrs = null)
        {
            Random rondom = new Random();
            Adspot adspot = host.CreateAdspot();
            
            if (traffic == null)
            {
                adspot.Traffic = rondom.Next(100,1000);
            }
            else
            {
                adspot.Traffic = traffic.Value;
            }
            List<double> clickThroughtRates = ctrs;
            if (clickThroughtRates == null)
            {
                clickThroughtRates = new List<double>();
                for (int i = 0; i < locationCount; i++)
                {
                    double value = (double)rondom.Next(10000);
                    clickThroughtRates.Add(value / 10000);
                }
            }
            adspot.ClickThroughtRates = clickThroughtRates.OrderByDescending(p => p).ToList();
            for (int i = 0; i < host.Advertisers.Count - locationCount; i++)
            {
                adspot.ClickThroughtRates.Add(0);
            }
            //adspot.ClickThroughtRates = adspot.ClickThroughtRates;

            //List<AdvertiserBidding> advertisers = new List<AdvertiserBidding>();
            //for (int i = 0; i < 100; i++)
            //{
            //    //var advertiser = new AdvertiserBidding();
            //    //advertiser.ExpectedRevenue = rondom.Next(100);
            //    //advertiser.Bid = advertiser.ExpectedRevenue;
            //    //advertisers.Add(advertiser);
            //}
            //adspot.Bitting = advertisers;
            //Adspot = adspot;
            return adspot;
        }
    }
}
